<template>
  <div class="card content-box">
    <el-form ref="ruleFormRef" :model="ruleForm" label-width="140px">
      <el-form-item label="提问审核开关" prop="switchAnswer">
        <el-switch v-model="ruleForm.switchQuestion" :active-value="true" :inactive-value="false" />
      </el-form-item>
      <el-form-item label="回答审核开关" prop="switchQuestion">
        <el-switch v-model="ruleForm.switchAnswer" :active-value="true" :inactive-value="false" />
      </el-form-item>
      <el-form-item label="小课堂审核开关" prop="switchLesson">
        <el-switch v-model="ruleForm.switchLesson" :active-value="true" :inactive-value="false" />
      </el-form-item>
      <el-form-item label="注册审核开关" prop="switchRegister">
        <el-switch v-model="ruleForm.switchRegister" :active-value="true" :inactive-value="false" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm"> 保存更改 </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts" name="dynamicForm">
import { ref, onMounted } from "vue";
// import { checkPhoneNumber } from "@/utils/eleValidate";
import type { FormInstance } from "element-plus";
import { getSet, updateSet } from "@/api/modules/sys";
import { ElMessage } from "element-plus";

const ruleFormRef = ref<FormInstance>();
let ruleForm = ref({});

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  try {
    await updateSet(ruleForm.value);
    ElMessage.success("修改成功");
  } catch (e) {
    ElMessage.success("修改失败");
  }
};
onMounted(async () => {
  const { data } = await getSet();
  ruleForm.value = data;
  console.log(data);
});
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
